import yaml
import os
import shutil

class fileOperation:
    # def __init__(self):

    def readYaml(self,filePath):
        # with open('test_cases/groups.yml', 'r', encoding='utf-8') as f:
        # with open('./test.yaml', 'r', encoding='utf-8') as f:
        with open(filePath, 'r', encoding='utf-8') as f:
            readResult = list(yaml.safe_load_all(f))
            return readResult

    def shutil_older(self,*path):
        """
        删除文件夹下，包含文件
        :param path:传入的路径（*元组传参）
        :return: Fale:失败   True：成功
        """
        try:
            for eachpath in path:
                # param1:删除文件的路径
                is_Exist = os.path.exists(eachpath)  # 先判断是否该文件存在
                if is_Exist:
                    # true：忽略错误
                    shutil.rmtree(eachpath, True)
            return True
        except:
            return False

    def mkdir_folder(self,*path):
        """
        当文件夹不存在时，进行文件夹创建，
        1. 可创建多级目录
        2. 可传入多个路径
        :param path: 传入的是元组
        :return: Fale:失败   True：成功
        """
        try:
            for eachpath in path:
                # 判断该文件夹是否存在
                is_Exist = os.path.exists(eachpath)
                # 不存在时创建该文件夹
                if not is_Exist:
                    # 创建多级文件及
                    os.makedirs(eachpath)
            return True
        except:
            return False



if __name__ == '__main__':
    pass
    # abobo = fileOperation()
    # import os
    # path = (os.path.dirname(os.path.abspath(__file__)))
    # print(abobo.readYaml(r'D:\autotest_yikai\pyTest\test_cases\test_error.yaml'))

